--应行而动
local yingxingerdong = fk.CreateSkill {
    name = "mcdh_yingxingerdong",
    tags ={Skill.Compulsory}
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

yingxingerdong:addEffect(fk.TargetConfirmed,{
    can_trigger = function(self, event, target, player, data)
        if target == player and player:hasSkill(self) then
            return data.from ~= player
        end
    end,
    on_cost = function(self, event, target, player, data)
        return true
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:addPlayerMark(player, "#yingxingerdong_distance-turn", 1)
        lib.LoadAmmo(player, player, 1, self.name)
    end
})

yingxingerdong:addEffect(lib.AfterAmmoAndCharge,{
    can_trigger = function(self, event, target, player, data)
        if target ~= player or not player:hasSkill(self) then return false end
        if lib.mcdh_getLoseammo(player) > 0 or data.type ~= "ammo" then return false end
            for _, current in ipairs(player.room:getAlivePlayers()) do
                if current:getMark("@mcdh_Damocles") > 0 then
                    return true
                end
            end
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
            local targets = table.filter(room:getAlivePlayers(), function(current)
                return current:getMark("@mcdh_Damocles") > 0
            end)
            local result =  room:askToChoosePlayers(player, {
                targets = targets,
                min_num = 1,
                max_num = 1,
                prompt = "#mcdh_yingxingerdong-ask",
                skill_name = self.name,
                cancelable = false
              })
            if #result > 0 then
                self.cost_data = result
                return true
            end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
            local target = self.cost_data[1]
            room:removePlayerMark(target, "@mcdh_Damocles", 1)
            if not target:isKongcheng() then
                local num = #target:getCardIds { Player.Hand, Player.Equip }
                num = math.min(4, num)
                room:askForDiscard(target, num, num, true, self.name, false, ".")
            end
            lib.Damage({
                from = player,
                to = target,
                damage = 1,
                skillName = self.name
            })
    end
})

yingxingerdong:addEffect('distance',{
    correct_func = function(self, from, to)
        return to:getMark("#yingxingerdong_distance-turn")
    end,
})

Fk:loadTranslationTable {
    ["mcdh_yingxingerdong"] = "机行",
    [":mcdh_yingxingerdong"] = "『应行而动』<br>锁定技。当你成为其他角色使用牌的目标后，本回合其他角色计算至你的距离+1，然后你装填1枚弹药；当你装填弹药至上限时，你可以移去一名角色的「锁定」标记，并令其弃置四张牌（无则不弃，不足则全弃），对其造成1点伤害。",
    ["#mcdh_yingxingerdong-ask"] = "机行：令被「锁定」的角色弃置四张牌并受到1点伤害"
}

return yingxingerdong